在vba中通过函数传递数组 您所在的位置:网站首页 vba 传递数组参数 在vba中通过函数传递数组

在vba中通过函数传递数组

2023-10-10 02:28| 来源: 网络整理| 查看: 265

我正在尝试调用一个函数来处理数组中的一些数据,出于很多不同的原因,我会重复这一过程,所以我只是想做好基本的准备,但我遇到了数据类型方面的错误。我已经简化了我的代码,试图让它从头开始,但仍然找不到原因。

Sub VBA_Split_Print() Dim last_row As Long last_row = Cells(Rows.Count, 1).End(xlUp).Row Range("J2:AE90000").ClearContents For J = 2 To last_row Dim arr() As String arr = Split(Worksheets("Raw").Cells(J, 9).Value, ",") Call ElectiveAdd(arr) Next J End Sub Function ElectiveAdd(ByRef arr() As String) Dim arrLength As Integer arrLength = UBound(arr, 1) - LBound(arr, 1) Dim x As Integer x = 0 For i = 24 To (arrLength + 24) Worksheets("Raw").Cells(J, i).Value = arr(x) x = x + 1 Next i End Function

当我试图运行它时,我得到了一个运行时错误'1004‘应用程序定义或对象定义的错误消息。

因此,由于反馈而修改了代码,我觉得J是另一个问题,所以我将其排除在外,谢谢您指出错误!

Sub VBA_Split_Print() Dim last_row As Long last_row = Cells(Rows.Count, 1).End(xlUp).row Range("J2:AE90000").ClearContents Dim arr() As String arr = Split(Worksheets("Raw").Cells(2, 9).Value, ",") Call ElectiveAdd(arr) End Sub Function ElectiveAdd(ByRef arr() As String) Dim arrLength As Integer arrLength = UBound(arr, 1) - LBound(arr, 1) Dim x As Integer x = 0 For i = 24 To (arrLength + 24) + 1 Worksheets("Raw").Cells(2, i).Value = arr(x) x = x + 1 Next i End Function

现在我收到下标超出范围的不同错误消息,单元格2,9 =“



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有